package com.sq.universe.flowable.service.impl;

import com.alibaba.fastjson.JSON;
import com.sq.universe.base.service.impl.BaseServiceImpl;
import com.sq.universe.flowable.dao.TestFlowableDao;
import com.sq.universe.flowable.entity.TestFlowableEntity;
import com.sq.universe.flowable.entity.WorkflowEntity;
import com.sq.universe.flowable.service.TestFlowableService;
import com.sq.universe.flowable.service.WorkflowService;
import com.sq.universe.system.entity.UserEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
* @author 孙乾 2020-11-05 22:11:42
*/
@Service
public class TestFlowableServiceImpl extends BaseServiceImpl<TestFlowableEntity, TestFlowableDao> implements TestFlowableService {

    @Autowired
    private TestFlowableDao testFlowableDao;

    @Autowired
    private WorkflowService workflowService;

    public Integer insert(TestFlowableEntity testFlowableEntity, UserEntity userEntity){
        testFlowableDao.insert(testFlowableEntity);
        WorkflowEntity workflowEntity = new WorkflowEntity();
        workflowEntity.setCls(TestFlowableEntity.class);
        workflowEntity.setParams(new HashMap());
        workflowEntity.getParams().put("projectName","流程测试");
        workflowEntity.getParams().put("title","测试数据：" + testFlowableEntity.getTfCode());
        workflowEntity.setBussinessKey(testFlowableEntity.getTfId().toString());
        workflowService.start(workflowEntity,userEntity);
        return testFlowableEntity.getTfId();
    }

}
